package com.iraeta.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iraeta.entity.Iraorderproduct;
import com.iraeta.entity.vo.IraOrderProductStep;
import com.iraeta.service.iraorder.IraProductStepService;
import com.iraeta.service.iraorder.IraorderproductService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/*
 * 订单的生产步骤维护功能
 * */
@RestController(value = "IraOrderProductController")
@RequestMapping("emp/orderproduct")
public class IraOrderProductController extends BaseController{
    @Resource
    IraorderproductService iraorderproductService;
    @Resource
    IraProductStepService iraProductStepService;        //物流步骤

    @RequestMapping("listproduct")
    public String listProduct(@RequestBody JSONObject paramJb){
        int orderId = paramJb.getIntValue("id");
        List<Iraorderproduct> iraorderproductList = iraorderproductService.listIraorderproductByOrderId(orderId);
        return this.success(iraorderproductList);
    }

    @RequestMapping("deleteproduct")
    public String deleteProduct(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        this.iraorderproductService.deleteIraorderproduct(id);
        return this.success();
    }

    /*产品步骤的数量填报功能*/
    @RequestMapping("listproductstepcount")
    public String listProductStepCount(@RequestBody JSONObject paramJb){
        int id = paramJb.getIntValue("id");
        List<IraOrderProductStep> iraOrderProductStepList = iraProductStepService.listIraOrderProductStep(id);
        return this.success(iraOrderProductStepList);
    }

    @RequestMapping("saveproductstepcount")
    public String saveProductStepCount(@RequestBody JSONObject paramJb){
        JSONArray stepCountJSONArray = paramJb.getJSONArray("stepCountList");
        iraProductStepService.saveIraOrderProductStep(stepCountJSONArray);
        return this.success();
    }
}
